package com.rpframework.website.device.act.api;

import java.util.List;
import java.util.TimeZone;

import com.google.gson.JsonParser;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.rpframework.core.BaseAct;
import com.rpframework.core.utils.DictionarySettingUtils;
import com.rpframework.core.utils.TagUtils;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.IInteractDao;
import com.rpframework.website.device.dao.IPraiseDao;
import com.rpframework.website.device.domain.Interact;
import com.rpframework.website.device.domain.Stream;
import com.rpframework.website.device.domain.Unit;
import com.rpframework.website.device.domain.User;
import com.rpframework.website.device.exception.APICodeException;
import com.rpframework.website.device.service.EstateService;
import com.rpframework.website.device.service.InteractService;
import com.rpframework.website.device.service.PraiseService;
import com.rpframework.website.device.service.StreamService;
import com.rpframework.website.device.service.TCommentService;
import com.rpframework.website.device.service.UnitService;
import com.rpframework.website.device.service.UserService;
/**
 * 互动api类
 * @author 
 * @date 
 */
@Controller
@RequestMapping("/api/interact")
public class InteractApiAct extends BaseAct{
	@Resource InteractService service;
	@Resource PraiseService praiseService;
	@Resource TCommentService tcommentService;
	@Resource UserService userService;
	@Resource EstateService estateService;
	
	@Resource UnitService unitService;
	@Resource StreamService StreamService;
	public @Resource IInteractDao iDao;
	public @Resource IPraiseDao IPraiseDao;
	 Gson gson=new Gson();
	/* 按type查询*/
	/**
	 * 查看互动列表 我发布的互动
	 * @param pager
	 * @param type
	 * @param my
	 * @param all
	 * @param callback
	 * @param session
	 * @return
	 * @time 2016年3月17日 上午11:26:29
	 */
	 
	@RequestMapping(value="/list" , produces = "application/json; charset=utf-8")
	public @ResponseBody String list(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value="type",required = false ) Integer type,//参数type
			@RequestParam(value="my",required = false ) String my,//查我发布的
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
	 
		if(pager==null){
			pager=new Pager<Interact>();}
		if(NumberUtils.isNotValid(type)&&StringUtils.isBlank(my))throw new APICodeException(-6, "type,my必填其中一个参数!");
		if(StringUtils.isNotBlank(my)){//如果参数有my 就是查我发布的
			   if (user == null) {
			        throw new APICodeException(-4, "你还没登陆!"); }
		pager.getSearchMap().put("userId", String.valueOf(user.getId()));}
		if(NumberUtils.isValid(type))//虽然type为null也不影响 但验证一下更安全 
		if(type==1)pager.getSearchMap().put("status", String.valueOf(1));
		else if(type==30)pager.getSearchMap().put("status", String.valueOf(2));
		else pager.getSearchMap().put("type", String.valueOf(type));
		pager.getSearchMap().put("state", "1");//默认查询正常状态的数据
		List<Interact> list = service.getpager(pager).getItemList();
		JsonObject json =new JsonObject();
		json.addProperty("total", pager.getTotalCount());
		json.addProperty("pages", pager.getTotalPages());
		json.addProperty("curr",  pager.getCurrentPage());
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type"+t.getType());
			obj.addProperty("brandName", brandName);
			
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("headImg", TagUtils.getFileFullPath(u.getHeadImg()));
				obj.addProperty("tel", u.getTel());
				obj.addProperty("constellation", u.getConstellation());
				obj.addProperty("point", u.getPoint());//积分
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			
			JsonArray arr = new JsonParser().parse(t.getUrlList()).getAsJsonArray();//逗号分隔的json型的对象
			JsonArray a = new JsonArray();
			for(JsonElement li : arr){
				a.add(new JsonPrimitive(TagUtils.getFileFullPath(li.toString().replace("\"", ""))));
			}
			obj.add("urlList", a);

			
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
			obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
			if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
			obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
			if(user != null){
			obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
			if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 如果查询结果为Null 则当前用户无操作 1可以收藏  2以收藏
			array.add(obj);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	/**
	 * 按照关联id查询唯一发布信息
	 * @param id
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/detail" , produces = "application/json; charset=utf-8")
	public @ResponseBody String detail(	
			@RequestParam(value="id",required = false ) Integer id,//查我发布的
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);

	    if(NumberUtils.isNotValid(id)){
	    	throw new APICodeException(-6, "id为必填参数!");
	    }
    	Interact t = service.select(id);
    	JsonObject obj = new JsonObject();
    	if(t!=null && t.getUserId()!=null){
			obj.addProperty("userId",t.getUserId());
			User u = userService.select(t.getUserId());
			if(u==null){
				
			}//如果发布的用户不存在了，这个信息也不要显示了
			obj.addProperty("uimg", TagUtils.getFileFullPath(u.getHeadImg()));
			obj.addProperty("uname", u.getRealName());//
		}else{
			obj.addProperty("code", -1);
			obj.addProperty("msg", "用户或互动无效！");
		}
		obj.addProperty("id", t.getId());
		obj.addProperty("type",t.getType());
		String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
		obj.addProperty("brandName", brandName);
		obj.addProperty("title",t.getTitle());
		obj.addProperty("content",t.getContent());
		obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
		
		obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
		obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
		obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查点赞总数  status=2 为收藏  status=3为点赞
		if(user != null){
			obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
			if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
			obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
			if(user != null){
			obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
			if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以点赞 2不能点赞
		if(StringUtils.isNotBlank(callback))return (callback + "(" + obj + ")");
		return ""+obj ;
	}
	
	@RequestMapping(value="/add" , produces = "application/json; charset=utf-8")
	public @ResponseBody String add(	
			@RequestParam(value = "callback",required = false ) String callback,
			@RequestParam(value = "type",required = false ) Integer type,//关联表(类型）
			@RequestParam(value = "village",required = false ) String village,//位置信息
			@RequestParam(value = "content",required = false ) String content,//内容
			@RequestParam(value = "urlList",required = false ) String urlList,//图片地址
			@RequestParam(value = "title",required = false ) String title,//标题
			HttpSession session
			){
		User user = getSessionUser(session);
		if (user == null) {
			throw new APICodeException(-4, "你还没登陆!");
		}
		if(StringUtils.isBlank(content) ||NumberUtils.isNotValid(type) ){
			throw new APICodeException(-9, "参数列表错误!content,type不能为空");
		}
		Interact t = new Interact();
		t.setVillage(village);
		t.setContent(content);
		t.setUrlList(urlList);
		t.setTitle(title);
		t.setType(type);//关联表(类型）
		t.setCreateTime(System.currentTimeMillis()/1000);
		t.setState(1);
		t.setStatus(2);
		t.setUserId(user.getId());
		boolean flag = service.insert(t);
/**
 * 增加积分  不论发多少条  都增加	
 */
		long curr = System.currentTimeMillis();
		long zero = (curr-TimeZone.getDefault().getRawOffset())/1000;
		Integer size = iDao.queryIntegral(user.getId(),zero);//查询我是否可以通过发布，获取积分
		
		//如果小于1则没有评论过    评论加积分
			//增加积分
		if(size<5){
			Unit unit = unitService.select(1);//评论一条增加积分数
			Integer userUnit = user.getPoint();//获取当前用户积分
			userUnit+=unit.getFB();//增加积分
			user.setPoint(userUnit);//修改积分
			userService.update(user);//提交数据
			//添加积分增加流水
			Stream Stream = new Stream();
			Stream.setTitle("发布信息 ");
			Stream.setCreateTime(System.currentTimeMillis()/1000);
			Stream.setUserId(user.getId());
			Stream.setInfo("+"+unit.getFB());
			StreamService.insert(Stream);
		}
		
		
		
		JsonObject obj = new JsonObject();
		if(flag){
			
			obj.addProperty("code", 200);
			obj.addProperty("zero", zero);
			obj.addProperty("size", size);
			obj.addProperty("msg", "添加成功");
		}else{
			obj.addProperty("code", 500);
			obj.addProperty("msg", "添加失败");
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + obj + ")");
		return ""+obj ;
	}
	

	//删除单个信息
	@RequestMapping(value="/delectCartOne",produces = "application/json; charset=utf-8")
	public @ResponseBody String delectCartOne(
			@RequestParam(value = "callback",required = false ) String callback,
			@RequestParam(required=false) Integer id,
			HttpSession session){
		User sessionuser=getSessionUser(session);
		if(sessionuser==null){
			throw new APICodeException(-4, "你还没登陆!");
		}
		boolean bfgl = service.delete(id);
		JsonObject json=new JsonObject();
		if(bfgl){
			json.addProperty("succ", true);
		}else{
			json.addProperty("succ", true);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	

	/**
	 *查询我的   需求收藏type小于8
	 * @param pager
	 * @param type
	 * @param my
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/xuqiu" , produces = "application/json; charset=utf-8")
	public @ResponseBody String list1(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value="status",required = false ) Integer status,//2收藏   
			@RequestParam(value="type",required = false ) Integer type,//参数type
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
	    if (user == null) {
	        throw new APICodeException(-4, "你还没登陆!"); }
		if(pager==null)pager=new Pager<Interact>();
		if(NumberUtils.isNotValid(status))throw new APICodeException(-6, "status必填!");
		//if(StringUtils.isNotBlank(my))//如果参数有my 就是查我发布的
	//	pager.getSearchMap().put("userId", String.valueOf(user.getId()));
		if(NumberUtils.isValid(type))//虽然type为null也不影响 但验证一下更安全 
	//	pager.getSearchMap().put("type", String.valueOf(29));
		pager.getSearchMap().put("state", "1");//默认查询正常状态的数据
		//if(type==8){List<Interact>  list = iDao.doPraiseByUsers(status, type,(Integer)user.getId());}
		List<Interact>  list = iDao.doPraiseByInteract(status, 29,(Integer)user.getId());
	//	List<Interact> list = service.getpager(pager).getItemList();
		JsonObject json =new JsonObject();
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
			obj.addProperty("brandName", brandName);
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("uimg", TagUtils.getFileFullPath(u.getHeadImg()));
				obj.addProperty("tel", u.getTel());
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
				obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
				obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
				if(user != null){
				obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以收藏  2以收藏
			array.add(obj);
		}
		
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	/**
	 *查询我的   互动收藏type大于7
	 * @param pager
	 * @param type
	 * @param my
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/hudong" , produces = "application/json; charset=utf-8")
	public @ResponseBody String list2(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value="status",required = false ) Integer status,//2收藏   
			@RequestParam(value="type",required = false ) Integer type,//参数type
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
	    if (user == null) {
	        throw new APICodeException(-4, "你还没登陆!"); }
		if(pager==null)pager=new Pager<Interact>();
		if(NumberUtils.isNotValid(status))throw new APICodeException(-6, "status必填!");
		//if(NumberUtils.isValid(29))//虽然type为null也不影响 但验证一下更安全 
		//pager.getSearchMap().put("type", String.valueOf(type));
		pager.getSearchMap().put("state", "1");//默认查询正常状态的数据
		List<Interact>  list = iDao.doPraiseByUsers(status, 29,(Integer)user.getId());
		JsonObject json =new JsonObject();
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
			obj.addProperty("brandName", brandName);
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("headImg", TagUtils.getFileFullPath(u.getHeadImg()));
				obj.addProperty("tel", u.getTel());
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
				obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
				obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
				if(user != null){
				obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以收藏  2以收藏
			array.add(obj);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	/**
	 *查询我发布的互动信息
	 * @param pager
	 * @param type
	 * @param my
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/fabu" , produces = "application/json; charset=utf-8")
	public @ResponseBody String list4(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value = "type",required = false ) Integer type,
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
		if (user == null) {
			throw new APICodeException(-4, "你还没登陆!"); }
		if(pager==null)pager=new Pager<Interact>();
		List<Interact>  list = iDao.doPraiseAdd((Integer)user.getId(),29);
		JsonObject json =new JsonObject();
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
			obj.addProperty("brandName", brandName);
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("uimg", TagUtils.getFileFullPath(u.getHeadImg()));
				obj.addProperty("tel", u.getTel());
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
				obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
				obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
				if(user != null){
				obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以收藏  2以收藏
			array.add(obj);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	/**
	 *查询我评论的互动信息
	 * @param pager
	 * @param type
	 * @param my
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/pinglunhudong" , produces = "application/json; charset=utf-8")
	public @ResponseBody String list3(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value = "type",required = false ) Integer type,
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
		if (user == null) {
			throw new APICodeException(-4, "你还没登陆!"); }
		if(pager==null)pager=new Pager<Interact>();
		List<Interact>  list = iDao.doPraiseComment((Integer)user.getId(),29);
		JsonObject json =new JsonObject();
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
			obj.addProperty("brandName", brandName);
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("uimg", TagUtils.getFileFullPath(user.getHeadImg()));
				obj.addProperty("tel", u.getTel());
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
				obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
				obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
				if(user != null){
				obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以收藏  2以收藏
			array.add(obj);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	/**
	 *查询我评论的需求信息
	 * @param pager
	 * @param type
	 * @param my
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/pinglunxuqiu" , produces = "application/json; charset=utf-8")
	public @ResponseBody String list6(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value = "type",required = false ) Integer type,
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
		if (user == null) {
			throw new APICodeException(-4, "你还没登陆!"); }
		if(pager==null)pager=new Pager<Interact>();
		List<Interact>  list = iDao.doPraiseComments((Integer)user.getId(),29);
		JsonObject json =new JsonObject();
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
			obj.addProperty("brandName", brandName);
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("uimg", TagUtils.getFileFullPath(u.getHeadImg()));
				obj.addProperty("tel", u.getTel());
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
				obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
				obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
				if(user != null){
				obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以收藏  2以收藏
			array.add(obj);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
	/**
	 * 模糊查询
	 * @param pager
	 * @param type
	 * @param my
	 * @param callback
	 * @param session
	 * @return
	 */
	@RequestMapping(value="/listLike" , produces = "application/json; charset=utf-8")
	public @ResponseBody String listLike(
			@RequestParam(value="pager",required = false ) Pager<Interact> pager,
			@RequestParam(value="word",required = false ) String word,//查我发布的
			@RequestParam(value = "callback",required = false ) String callback,
			HttpSession session
			){
		User user = getSessionUser(session);
	 
		if(pager==null){
			pager=new Pager<Interact>();}
		if(StringUtils.isBlank(word))throw new APICodeException(-6, "word必填!");
		pager.getSearchMap().put("word",word );
		List<Interact> list = service.listLikePager(pager).getItemList();
		   if (list.size()<1) {
		        throw new APICodeException(-4, "查询不到信息!"); }
		JsonObject json =new JsonObject();
		json.addProperty("total", pager.getTotalCount());
		json.addProperty("pages", pager.getTotalPages());
		json.addProperty("curr",  pager.getCurrentPage());
		JsonArray array=new JsonArray();
		json.add("arrays", array);
		for (Interact t : list) {
			JsonObject obj = new JsonObject();
			obj.addProperty("id", t.getId());
			obj.addProperty("type",t.getType());
			String brandName=DictionarySettingUtils.getParameterValue("interact.type."+t.getType());
			obj.addProperty("brandName", brandName);
			obj.addProperty("title",t.getTitle());
			obj.addProperty("content",t.getContent());
			obj.addProperty("village",t.getVillage());
			obj.addProperty("time",TagUtils.formatDate(t.getCreateTime()));
			if(t.getUserId()!=null){
				obj.addProperty("userId",t.getUserId());
				User u = userService.select(t.getUserId());
				if(u==null)continue;//如果发布的用户不存在了，这个信息也不要显示了
				obj.addProperty("uname", u.getNickName());
				obj.addProperty("headImg", TagUtils.getFileFullPath(u.getHeadImg()));
				obj.addProperty("tel", u.getTel());
				obj.addProperty("constellation", u.getConstellation());
				obj.addProperty("point", u.getPoint());//积分
			}
			obj.addProperty("comment", tcommentService.queryAll(t.getId(),t.getType()));//
			obj.add("urlList", service.getUrlListFormat(t.getUrlList()));
			obj.addProperty("praiseCount",praiseService.priceCount(t.getId(), t.getType(),3));//评论表里type 查点赞总数
			if(user != null){
				obj.addProperty("isPraise",IPraiseDao.doIsPraises(t.getId(), user.getId(),3));}
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),3)==null)  obj.addProperty("isPraise",1);// 1可以点赞 2不能点赞
				obj.addProperty("favoriteCount",praiseService.priceCount(t.getId(), t.getType(),2));//评论表里type 查收藏总数  status=2 为收藏  status=3为点赞
				if(user != null){
				obj.addProperty("isFavorite",IPraiseDao.doIsPraises(t.getId(), user.getId(),2));}//先判断能否查到记录 再取值
				if(user == null||IPraiseDao.doIsPraises(t.getId(), user.getId(),2)==null) obj.addProperty("isFavorite",1);// 1可以收藏  2以收藏
			array.add(obj);
		}
		if(StringUtils.isNotBlank(callback))return (callback + "(" + json + ")");
		return ""+json ;
	}
}